import QtQuick 2.9
import QtQuick.Controls 2.5
import QtMultimedia 5.12

import "./layouts" as Layouts

Item {
    id: root

    signal back()
    signal backWithCode(string code)

    ///////////////////////////////////////// UI ////
    Layouts.TopLayout {
        id: toolBar
        z: 100
        width: parent.width
        height: root.height * 0.1
        title: qsTr("检测")

        onClickedBack: root.back()
    }

    Item {
        width: parent.width
        height: parent.height - toolBar.height
        y: toolBar.height

        Camera {
            id: camera
            imageProcessing.whiteBalanceMode:CameraImageProcessing.WhiteBalanceFlash
            exposure {
                exposureCompensation: -1.0
                exposureMode:Camera.ExposurePortrait
            }

            flash.mode: Camera.FlashRedEyeReduction
            imageCapture {
                onImageCaptured: {
                    photoPreview.source =preview  // Show the preview in an Image
                }
            }
        }

        VideoOutput {
            source: camera
            anchors.fill: parent
            focus : visible // to receive focus andcapture key events when visible
        }

        Image {
            id: photoPreview
        }

        Rectangle {
            id: layoutMain
            width: root.width * 0.5
            height: width
            anchors.centerIn: parent
            border.color: "#2E75B6"
            border.width: 1
            color: "transparent"

            MouseArea {
                anchors.fill: parent
                onClicked: backWithCode("A002019Q401")
            }
        }

        Text {
            id: txtTip
            width: parent.width
            height: parent.height * 0.2
            anchors.top: layoutMain.bottom
            anchors.topMargin: parent.height * 0.05
            horizontalAlignment: Text.AlignHCenter
            text: qsTr("将二维码/条码放入框中，即可自动扫描")
        }
    }
}
